home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14246 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  61 lines

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John L. Noland)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: #include "" for large programs.
  5. Date: 12 Apr 1996 19:42:51 GMT
  6. Organization: Uno mas por favor
  7. Message-ID: <4kmbnr$89@newshost.cyberramp.net>
  8. References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan>
  9. NNTP-Posting-Host: ramp3-16.cyberramp.net
  10. X-Newsreader: WinVN 0.99.5
  11.  
  12. In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan>, cdiaz@eng.usf.edu says...
  13. >
  14. > I've been writing short two part programs using the #include "filename"
  15. >preprocessor.
  16. > I call one file main.c and the other part2.c, for which there is a
  17. >prototype header file part2.h.
  18. > All works well when I compile the programs, except when  part2.h has
  19. >#define constants (I've been advised by my professor to use #define for
  20. >constants over 'const type var_name'). My compiler returns a fatal error
  21. >reporting that the symbol in the #define is not defined.
  22. > For example if #define EQUAL 0 is part of part2.h, I'm told that the
  23. >symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
  24. >told that I've defined EQUAL  TWICE, once in part2.h and again within
  25. >main. The book we're using in class is not helping at all in this subject,
  26. >and I cannot figure out why everything else is recognized, except #define
  27. >constants. Can anyone here help? If the answer to this is in the FAQ, just
  28. >tell me where to download it from. Thanks!
  29.  
  30. Where are your header files located? It could be that the compiler
  31. isn't finding them. Usually you do something like this:
  32.  
  33. #include <part2.h>
  34.  
  35. which tells the compiler to look in the usual place for the 
  36. file. I don't know what compiler you're using, but most have a
  37. place to put in the path to the include files. If your header
  38. is located in a different directory than this you need to do
  39. this:
  40.  
  41. #include "part2.h"
  42.  
  43. this tells it to look in the current working directory. You
  44. could put the explicit path like this:
  45.  
  46. #include "c:/student/diaz/part2.h"
  47.  
  48. Also in your header files you could do the following:
  49.  
  50. #ifndef PART2_H
  51. #define PART2_H
  52.  
  53. .....
  54.  
  55. #endif
  56.  
  57. This will prevent a header from being included twice.
  58.  
  59. -John
  60.  
  61.